package com.bigcat.gulimall.demo;


import com.bigcat.gulimall.demo.pojo.Transaction;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Athor:Yuan
 * @Date:2020/9/10 17:40
 * Desc:
 */
public class Lambda {

    public static void main(String[] args) {
        ArrayList<Transaction> transactions = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            Transaction transaction = new Transaction();
            transaction.setId(i);
            transaction.setName("demo"+i);
            transaction.setType(i);
            transaction.setValue(i);
            transactions.add(transaction);
        }
//        List<Transaction> groceryTransactions = new ArrayList<>();
//        for (Transaction t : transactions) {
//            if (t.getType() == Transaction.GROCERY) {
//               groceryTransactions.add(t);
//            }
//        }
//        Collections.sort(groceryTransactions, new Comparator<Transaction>() {
//            @Override
//            public int compare(Transaction o1, Transaction o2) {
//
//                return o1.getValue().compareTo(o1.getValue());
//            }
//        }
//    );
//
//        List<Integer> transactionIds = new ArrayList<>();
//        for (Transaction t : groceryTransactions) {
//              transactionIds.add(t.getId());
//        }
        long l = System.currentTimeMillis();
        List<Integer> transactionsIds = transactions.parallelStream().
                filter(t -> t.getType().equals(Transaction.GROCERY)).
//                sorted(Comparator.comparing(Transaction::getValue).reversed()).
                map(Transaction::getId).
                collect(Collectors.toList());

        transactions.stream().max(Comparator.comparing(Transaction::getId));
        System.out.println(transactionsIds);
        long l1 = System.currentTimeMillis();
        System.out.println(l1-l);


    }


}